package edu.bbu.commonproject.desktop.gui.view.swing.login;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import edu.bbu.commonproject.desktop.gui.view.swing.utils.Design;

/**
 * The login panel, filled with components.
 */
public class LoginPanel extends JPanel
{
	/** The base image. */
	private Image baseImage;
	
	/** The usernames label. */
	private JLabel userNameLabel;
	
	/** The user names textfield. */
	private JTextField userNameTextField;
	
	/** The password label. */
	private JLabel passwordLabel;
	
	/** The password text field. */
	private JPasswordField passwordTextField;
	
	/** The logon user button. */
	private JButton logonUserButton;
	
	/** The error label. */
	private JLabel errorLabel;
	
	/**
	 * The constructor.
	 */
	public LoginPanel()
	{
		baseImage = Design.COMPONENT_LOGIN;
		
		this.setSize(new Dimension(600, 400));
		this.setLayout(null);
		
		setComponents();
	}
	
	/**
	 * Sets up the components and ands it to the panel.
	 */
	public void setComponents()
	{
		userNameLabel = new JLabel("Username");
		userNameLabel.setSize(new Dimension(70,30));
		userNameLabel.setLocation(130, 124);
		userNameLabel.setForeground(Color.WHITE);
		userNameLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
		
		userNameTextField = new JTextField();
		userNameTextField.setSize(new Dimension(280,30));
		userNameTextField.setLocation(215, 125);
		
		passwordLabel = new JLabel("Password");
		passwordLabel.setSize(new Dimension(70,30));
		passwordLabel.setLocation(130, 159);
		passwordLabel.setForeground(Color.WHITE);
		passwordLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
		
		passwordTextField = new JPasswordField();
		passwordTextField.setSize(new Dimension(280,30));
		passwordTextField.setLocation(215, 160);
		
		logonUserButton = new JButton("Login");
		logonUserButton.setSize(new Dimension(145,40));
		logonUserButton.setLocation(350, 210);
		
		errorLabel = new JLabel("Incorrect username or password.");
		errorLabel.setSize(new Dimension(200,40));
		errorLabel.setLocation(295, 265);
		errorLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		errorLabel.setForeground(Color.ORANGE);
		errorLabel.setFont(new Font("SansSerif", Font.BOLD, 12));
		errorLabel.setVisible(false);
	
		this.add(userNameLabel);
		this.add(userNameTextField);
		this.add(passwordLabel);
		this.add(passwordTextField);
		this.add(logonUserButton);
		this.add(errorLabel);
	}
	
	/**
	 * Gets the username texfiield.
	 * @return the username texfiield.
	 */
	public JTextField getUserNameTextField() 
	{
		return userNameTextField;
	}
	
	/**
	 * Gets the password field.
	 * @return the password field.
	 */
	public JPasswordField getPasswordTextField() 
	{
		return passwordTextField;
	}
	
	/**
	 * Gets the login button.
	 * @return the login button.
	 */
	public JButton getLoginButton() 
	{
		return logonUserButton;
	}
	
	/**
	 * Gets the error label.
	 * @return the error label.
	 */
	public JLabel getErrorLabel()
	{
		return errorLabel;
	}
	
	/**
	 * The overrided paintComponent.
	 */
	protected void paintComponent(Graphics g)
	{
		g.drawImage(baseImage, 0, 0, null);
	}
}
